package com.sengled.cloud.biz.union.mgt.dao.sys.provider;

import com.sengled.cloud.biz.union.mgt.model.po.RoleModulePermission;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * Created by csolo on 2017/11/9.
 */
public class RoleModulePermissionDaoProvider {

    public String batchInsert(Map map) {
        List<RoleModulePermission> roleModulePermissions = (List<RoleModulePermission>) map.get("list");
        StringBuilder sb = new StringBuilder();
        if (null != roleModulePermissions && !roleModulePermissions.isEmpty()) {
            sb.append("INSERT INTO role_module_permission(role_id,module_id,permission_id,create_date) VALUES");
            /*MessageFormat mf = new MessageFormat("(#'{'list[{0}].roleId},#'{'list[{0}].moduleId},#'{'list[{0}].permissionId},#'{'list[{0}].createDate})");
            for (RoleModulePermission roleModulePermission : roleModulePermissions) {
                    sb.append(mf.format(new Object[]{roleModulePermissions.indexOf(roleModulePermission)}));
                if (roleModulePermissions.indexOf(roleModulePermission) < roleModulePermissions.size() - 1) {
                    sb.append(",");
                }
            }*/
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            roleModulePermissions.forEach(roleModulePermission -> {
                 String cdate= sf.format(roleModulePermission.getCreateDate());
                sb.append("("+roleModulePermission.getRoleId()+","+roleModulePermission.getModuleId()+","+roleModulePermission.getPermissionId()+",'"+cdate+"'),");
            });
        }
        sb.deleteCharAt(sb.length()-1);
        System.out.println("sql : ---------------->"+sb.toString());
        return sb.toString();
    }
}
